<!DOCTYPE html>
<html>
    <head>
        <!-- 页面meta -->
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <title>传智健康</title>
        <meta name="description" content="传智健康">
        <meta name="keywords" content="传智健康">
        <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
        <!-- 引入样式 -->
        <link rel="stylesheet" href="../plugins/elementui/index.css">
        <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
        <link rel="stylesheet" href="../css/style.css">
    </head>
    <body class="hold-transition">
        <div id="app">
            <div class="content-header">
                <h1>会员管理<small>体检上传</small></h1>
                <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
                    <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>会员管理</el-breadcrumb-item>
                    <el-breadcrumb-item>体检上传</el-breadcrumb-item>
                </el-breadcrumb>
            </div>
            <div class="app-container">
                <div class="box">
                    <div class="filter-container">
                        <el-input placeholder="档案号/姓名/手机号" v-model="pagination.queryString" style="width: 200px;" class="filter-item"></el-input>
                        <el-button type="primary" class="butT" @click="findPage()">查询</el-button>
                        <el-button type="primary" class="butT" @click="handleCreate()">新建</el-button>
                        <el-button type="danger" class="butT" @click="handleDeleteChange()">删除选中</el-button>
                    </div>
                    <el-table size="small" ref="multipleTable" @selection-change="handleSelectionChange" current-row-key="id" :data="dataList" stripe highlight-current-row>
                        <el-table-column type="selection" width="55"></el-table-column>
                        <el-table-column prop="checkDate" label="体检时间" align="center"></el-table-column>
                        <el-table-column prop="fileNumber" label="档案号" align="center"></el-table-column>
                        <el-table-column prop="mname" label="姓名" align="center"></el-table-column>
                        <el-table-column prop="phoneNumber"  label="手机号" align="center"></el-table-column>
                        <el-table-column prop="sname" label="检测套餐" align="center"></el-table-column>
                        <el-table-column prop="uploadStatus" label="报告状态" align="center"></el-table-column>
                        <el-table-column label="操作" align="center">
                            <template slot-scope="scope">
                                <el-button type="primary" size="mini" @click="handleUpdate(scope.row)">上传报告</el-button>
                                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            class="pagiantion"
                            @current-change="handleCurrentChange"
                            :current-page="pagination.currentPage"
                            :page-size="pagination.pageSize"
                            layout="total, prev, pager, next, jumper"
                            :total="pagination.total">
                        </el-pagination>
                    </div>
                    <!-- 新增标签弹层 -->
                    <div class="add-form">
                        <el-dialog title="上传报告" :visible.sync="dialogFormVisible">
                            <el-form ref="dataAddForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="姓名" prop="mname">
                                            <template>
                                                <el-select v-model="value" clearable placeholder="请选择" @change="getFileNum">
                                                    <el-option
                                                            v-for="item in options"
                                                            :label="item.name"
                                                            :value="item.id">
                                                    </el-option>
                                                </el-select>
                                            </template>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="档案号" prop="fileNumber">
                                            <el-input v-model="formData.fileNumber" disabled="1"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="体检时间" prop="checkDate">
                                            <el-input v-model="formData.checkDate" disabled="1"/>

                                            <!--<div class="block">
                                                <el-date-picker
                                                        v-model="initDate"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </div>-->
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="数据文件" prop="dataFile">
                                            <el-input v-model="fileName" disabled="1"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                            <div class="boxMain">
                                                <el-upload action="/physical/upload.do"
                                                           name="pdfFile"
                                                           :show-file-list="false"
                                                           :on-success="handleSuccess"
                                                           :before-upload="beforeUpload">
                                                    <el-button type="primary">上传文件</el-button>
                                                </el-upload>
                                            </div>
                                    </el-col>
                                </el-row>

                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible = false">取消</el-button>
                                <el-button type="primary" @click="add()">确定</el-button>
                            </div>
                        </el-dialog>
                    </div>
                    <!-- 上传报告标签弹层 -->
                    <div class="edit-form">
                        <el-dialog title="上传报告" :visible.sync="dialogFormVisible4Edit">
                            <el-form ref="dataEditForm" :model="formData" :rules="rules" label-position="right" label-width="100px">
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="姓名" prop="mname">
                                            <el-input v-model="formData.mname" disabled="1"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <el-form-item label="档案号" prop="fileNumber">
                                            <el-input v-model="formData.fileNumber" disabled="1"/>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="体检时间" prop="checkDate">
                                            <div class="block">
                                                <el-date-picker
                                                        v-model="formData.checkDate"
                                                        type="date"
                                                        placeholder="选择日期" disabled="1">
                                                </el-date-picker>
                                            </div>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-col :span="12">
                                        <el-form-item label="数据文件" prop="file">
                                            <el-input v-model="fileName" disabled="1"/>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span="12">
                                        <div class="boxMain">
                                            <el-upload action="/physical/upload.do"
                                                       name="pdfFile"
                                                       :show-file-list="false"
                                                       :on-success="handleSuccess"
                                                       :before-upload="beforeUpload">
                                                <el-button type="primary">上传文件</el-button>
                                            </el-upload>
                                        </div>
                                    </el-col>
                                </el-row>

                            </el-form>
                            <div slot="footer" class="dialog-footer">
                                <el-button @click="dialogFormVisible4Edit = false">取消</el-button>
                                <el-button type="primary" @click="edit()">保存</el-button>
                            </div>
                        </el-dialog>
                    </div>

                </div>
            </div>
        </div>
    </body>
    <!-- 引入组件库 -->
    <script src="../js/vue.js"></script>
    <script src="../plugins/elementui/index.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script src="../js/axios-0.18.0.js"></script>
    <script>
        var vue = new Vue({
            el: '#app',
            data:{
                pagination: {//分页相关模型数据
					  currentPage: 1,//当前页码
					  pageSize:10,//每页显示的记录数
					  total:0,//总记录数
					  queryString:null//查询条件
				},
				dataList: [],//当前页要展示的分页列表数据
                formData: {},//表单数据
                dialogFormVisible: false,//增加表单是否可见
                dialogFormVisible4Edit:false,//编辑表单是否可见
                rules: {//校验规则
                    //fileNumber: [{ required: true, message: '档案号为必填项', trigger: 'blur' }],
                      //mname: [{ required: true, message: '姓名为必填项', trigger: 'blur' }],
                     // checkDate: [{ required: true, message: '体检时间必填项', trigger: 'blur' }]
                },

                // initDate:'',
                fileName:"",
                multipleSelection: [],
                options: [],
                value:''


            },
            //钩子函数，VUE对象初始化完成后自动执行
            created() {
                this.findPage();
            },
            methods: {
                //选择姓名和档案号
                getFileNum(val){

                    //获取档案名
                    let obj = {};
                    obj = this.options.find((item)=>{
                        return item.id === val;
                    });
                    this.formData.fileNumber=obj.fileNumber;
                    this.formData.mname=obj.name;
                    this.formData.checkDate=obj.orderDate;

                },
                showMessage(r) {
                    if (r == 'Error: Request failed with status code 403') {
                        //权限不足
                        this.$message.error('无访问权限');
                        return;
                    } else {
                        this.$message.error('未知错误');
                        return;
                    }
                },
                // disabledDate(time) {
                //     return time.getTime() > Date.now();
                // },
                //上传之前进行文件格式校验
                beforeUpload(file) {
                    if (file.type === 'application/pdf') {
                        this.fileName=file.name;
                        return true;
                    }
                    this.$message.error('上传文件只能是pdf格式!');
                    return false;
                },
                //上传成功提示
                handleSuccess(response, file) {
                    if (response.flag) {
                        this.$message({
                            message: response.message,
                            type: 'success'
                        });
                    } else {
                        this.$message.error(response.message);
                    }
                    this.formData.file=response.data;
                    console.log(response, file, fileList);
                },
                // 弹出添加窗口
                handleCreate() {
                    axios.post("/physical/findAll.do").then((response)=>{
                        this.options=response.data.data;
                    });
                    this.dialogFormVisible = true;
                    this.resetForm();
                },
                //添加
                add () {
                    //进行表单校验
                    // var date=this.initDate;
                    // var time=this.formatDate(date.getFullYear(),date.getMonth()+1,date.getDate());
                    // this.formData.checkDate=time;
                        if(this.formData.mname){
                            //如果校验通过，发送ajax请求，将表单数据提交到Controller
                            axios.post("/physical/add.do",this.formData).then((res) => {
                                if(res.data.flag){
                                    //处理成功
                                    this.$message({
                                        type:'success',
                                        message:res.data.message
                                    });
                                    //关闭新增窗口
                                    this.dialogFormVisible = false;
                                    //分页查询
                                    this.findPage();
                                }else{
                                    //处理失败
                                    this.$message.error(res.data.message);
                                }
                            });
                        }else{
                            //校验不通过，提示错误信息
                            this.$message.error("表单数据校验失败，请检查输入是否正确！");
                        }
                },
                // 弹出上传报告窗口
                handleUpdate(row) {
                    this.dialogFormVisible4Edit = true;
                    this.formData=row;
                    this.fileName ='';
                    //回显数据
                    // axios.get("/physical/findById.do?id=" + row.id).then((res) => {
                    //     if(res.data.flag){
                    //         this.formData = res.data.data;//为模型数据赋值，基于VUE数据绑定进行回显
                    //     }else{
                    //         this.$message.error(res.data.message);
                    //     }
                    // });
                },
                //上传报告
                edit() {
                    //进行表单校验
                    // this.$refs['dataEditForm'].validate((valid) => {
                        if(this.formData.fileName){
                            //如果校验通过，发送ajax请求，将表单数据提交到Controller
                            axios.post("/physical/edit.do",this.formData).then((res) => {
                                if(res.data.flag){
                                    //处理成功
                                    this.$message({
                                        type:'success',
                                        message:res.data.message
                                    });
                                    //关闭新增窗口
                                    this.dialogFormVisible4Edit = false;
                                    //分页查询
                                    this.findPage();
                                }else{
                                    //处理失败
                                    this.$message.error(res.data.message);
                                }
                            });
                        }else{
                            //校验不通过，提示错误信息
                            this.$message.error("表单数据校验失败，请检查输入是否正确！");
                        }
                    // });
                },
                //分页查询
                findPage() {
                    //分页参数
                    var param = {
                        currentPage: this.pagination.currentPage,//页码
                        pageSize: this.pagination.pageSize,//每页显示的记录数
                        queryString: this.pagination.queryString//查询条件
                    };
                    //请求后台
                    axios.post("/physical/findPage.do", param).then((response) => {
                        //为模型数据赋值，基于VUE的双向绑定展示到页面
                        this.dataList = response.data.rows;
                        this.pagination.total = response.data.total;
                    }).catch((r) => {
                        this.showMessage(r);
                    });
                },
                // 重置表单
                resetForm() {
                    this.formData = {};
                    this.fileName = '';
                    this.value='';
                },

                //切换页码
                handleCurrentChange(currentPage) {
                    //currentPage为切换后的页码
                    this.pagination.currentPage = currentPage;
                    this.findPage();
                },
                // 删除
                handleDelete(row) {
                    this.$confirm("确认删除当前选中记录吗？", "提示", {type: 'warning'}).then(() => {
                        axios.get("/physical/deleteById.do?id=" + row.id).then((res) => {
                            if (!res.data.flag) {
                                //删除失败
                                this.$message.error(res.data.message);
                            } else {
                                //删除成功
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                                //调用分页，获取最新分页数据
                                this.findPage();
                            }
                        }).catch((r) => {
                            this.showMessage(r);
                        });
                    }).catch(() => {
                        //点击取消按钮执行此代码
                        this.$message('操作已取消');
                    });
                },
               /* formatDate: function (year, month, day) {
                    var y = year;
                    var m = month;
                    if (m < 10) m = "0" + m;
                    var d = day;
                    if (d < 10) d = "0" + d;
                    return y + "-" + m + "-" + d

                 },*/
                //全选获取选中行数据
                handleSelectionChange(val) {
                    this.multipleSelection = val;

                },
                //删除选中
                handleDeleteChange(){
                    let ids=[];
                    this.multipleSelection.map((item)=>{
                        ids.push(item.id)
                    });
                    this.$confirm("确认删除当前选中记录吗?","提示",{type:'warning'}).then(()=>{
                        axios.get("/physical/deleteByIds.do?ids=" + ids).then((res) => {
                            if (!res.data.flag) {
                                //删除失败
                                this.$message.error(res.data.message);
                            } else {
                                //删除成功
                                this.$message({
                                    message: res.data.message,
                                    type: 'success'
                                });
                                //调用分页，获取最新分页数据
                                this.findPage();
                            }
                        });
                    })
                },
            }
        })
    </script>
</html>